package com.example.weight.greenSeasons.deodorization;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.weight.R;
import com.example.weight.config.Config;
import com.example.weight.greenSeasons.compost.CompostWeekMaintenanceActivity;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import net.cachapa.expandablelayout.ExpandableLayout;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProductionFacilityCheck extends AppCompatActivity {

    private ExpandableLayout expandable_1,expandable_2,expandable_3;
    private Button ButtonNo1,ButtonNo2,ButtonNo3;

    //用户、抄表人
    private String name, factory;

    private List<RadioButton> normalButtons;
    private List<RadioButton> abnormalButtons;
    private List<TextView> names;

    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_production_facility_check);

        //用户和职责
        Intent previousIntent = getIntent();
        name = previousIntent.getStringExtra("name");
        factory = previousIntent.getStringExtra("factory");

        //正常异常按钮组
        RadioGroup radioGroup1 = findViewById(R.id.equipment1_group_button);
        RadioGroup radioGroup2 = findViewById(R.id.equipment2_group_button);
        RadioGroup radioGroup3 = findViewById(R.id.equipment3_group_button);
        RadioGroup radioGroup4 = findViewById(R.id.equipment4_group_button);
        RadioGroup radioGroup5 = findViewById(R.id.equipment5_group_button);
        RadioGroup radioGroup6 = findViewById(R.id.equipment6_group_button);
        RadioGroup radioGroup7 = findViewById(R.id.equipment7_group_button);
        RadioGroup radioGroup8 = findViewById(R.id.equipment8_group_button);
        RadioGroup radioGroup9 = findViewById(R.id.equipment9_group_button);
        RadioGroup radioGroup10 = findViewById(R.id.equipment10_group_button);
        RadioGroup radioGroup11 = findViewById(R.id.equipment11_group_button);
        RadioGroup radioGroup12 = findViewById(R.id.equipment12_group_button);
        RadioGroup radioGroup13 = findViewById(R.id.equipment13_group_button);
        RadioGroup radioGroup14 = findViewById(R.id.equipment14_group_button);
        RadioGroup radioGroup15 = findViewById(R.id.equipment15_group_button);
        RadioGroup radioGroup16 = findViewById(R.id.equipment16_group_button);
        RadioGroup radioGroup17 = findViewById(R.id.equipment17_group_button);
        RadioGroup radioGroup18 = findViewById(R.id.equipment18_group_button);
        RadioGroup radioGroup19 = findViewById(R.id.equipment19_group_button);
        RadioGroup radioGroup20 = findViewById(R.id.equipment20_group_button);
        RadioGroup radioGroup21 = findViewById(R.id.equipment21_group_button);
        RadioGroup radioGroup22 = findViewById(R.id.equipment22_group_button);
        RadioGroup radioGroup23 = findViewById(R.id.equipment23_group_button);
        RadioGroup radioGroup24 = findViewById(R.id.equipment24_group_button);
        RadioGroup radioGroup25 = findViewById(R.id.equipment25_group_button);
        RadioGroup radioGroup26 = findViewById(R.id.equipment26_group_button);
        RadioGroup radioGroup27 = findViewById(R.id.equipment27_group_button);
        RadioGroup radioGroup28 = findViewById(R.id.equipment28_group_button);
        RadioGroup radioGroup29 = findViewById(R.id.equipment29_group_button);
        RadioGroup radioGroup30 = findViewById(R.id.equipment30_group_button);
        RadioGroup radioGroup31 = findViewById(R.id.equipment31_group_button);
        RadioGroup radioGroup32 = findViewById(R.id.equipment32_group_button);
        List<RadioGroup> radioGroups = new ArrayList<>();
        radioGroups.add(radioGroup1);   radioGroups.add(radioGroup2);   radioGroups.add(radioGroup3);
        radioGroups.add(radioGroup4);   radioGroups.add(radioGroup5);   radioGroups.add(radioGroup6);
        radioGroups.add(radioGroup7);   radioGroups.add(radioGroup8);   radioGroups.add(radioGroup9);
        radioGroups.add(radioGroup10);  radioGroups.add(radioGroup11);  radioGroups.add(radioGroup12);
        radioGroups.add(radioGroup13);  radioGroups.add(radioGroup14);  radioGroups.add(radioGroup15);
        radioGroups.add(radioGroup16);  radioGroups.add(radioGroup17);  radioGroups.add(radioGroup18);
        radioGroups.add(radioGroup19);  radioGroups.add(radioGroup20);  radioGroups.add(radioGroup21);
        radioGroups.add(radioGroup22);  radioGroups.add(radioGroup23);  radioGroups.add(radioGroup24);
        radioGroups.add(radioGroup25);  radioGroups.add(radioGroup26);  radioGroups.add(radioGroup27);
        radioGroups.add(radioGroup28);  radioGroups.add(radioGroup29);  radioGroups.add(radioGroup30);
        radioGroups.add(radioGroup31);  radioGroups.add(radioGroup32);
        //所有正常异常按钮
        RadioButton btn1_1 = findViewById(R.id.equipment1_normal_button);
        RadioButton btn1_0 = findViewById(R.id.equipment1_abnormal_button);
        RadioButton btn2_1 = findViewById(R.id.equipment2_normal_button);
        RadioButton btn2_0 = findViewById(R.id.equipment2_abnormal_button);
        RadioButton btn3_1 = findViewById(R.id.equipment3_normal_button);
        RadioButton btn3_0 = findViewById(R.id.equipment3_abnormal_button);
        RadioButton btn4_1 = findViewById(R.id.equipment4_normal_button);
        RadioButton btn4_0 = findViewById(R.id.equipment4_abnormal_button);
        RadioButton btn5_1 = findViewById(R.id.equipment5_normal_button);
        RadioButton btn5_0 = findViewById(R.id.equipment5_abnormal_button);
        RadioButton btn6_1 = findViewById(R.id.equipment6_normal_button);
        RadioButton btn6_0 = findViewById(R.id.equipment6_abnormal_button);
        RadioButton btn7_1 = findViewById(R.id.equipment7_normal_button);
        RadioButton btn7_0 = findViewById(R.id.equipment7_abnormal_button);
        RadioButton btn8_1 = findViewById(R.id.equipment8_normal_button);
        RadioButton btn8_0 = findViewById(R.id.equipment8_abnormal_button);
        RadioButton btn9_1 = findViewById(R.id.equipment9_normal_button);
        RadioButton btn9_0 = findViewById(R.id.equipment9_abnormal_button);
        RadioButton btn10_1 = findViewById(R.id.equipment10_normal_button);
        RadioButton btn10_0 = findViewById(R.id.equipment10_abnormal_button);
        RadioButton btn11_1 = findViewById(R.id.equipment11_normal_button);
        RadioButton btn11_0 = findViewById(R.id.equipment11_abnormal_button);
        RadioButton btn12_1 = findViewById(R.id.equipment12_normal_button);
        RadioButton btn12_0 = findViewById(R.id.equipment12_abnormal_button);
        RadioButton btn13_1 = findViewById(R.id.equipment13_normal_button);
        RadioButton btn13_0 = findViewById(R.id.equipment13_abnormal_button);
        RadioButton btn14_1 = findViewById(R.id.equipment14_normal_button);
        RadioButton btn14_0 = findViewById(R.id.equipment14_abnormal_button);
        RadioButton btn15_1 = findViewById(R.id.equipment15_normal_button);
        RadioButton btn15_0 = findViewById(R.id.equipment15_abnormal_button);
        RadioButton btn16_1 = findViewById(R.id.equipment16_normal_button);
        RadioButton btn16_0 = findViewById(R.id.equipment16_abnormal_button);
        RadioButton btn17_1 = findViewById(R.id.equipment17_normal_button);
        RadioButton btn17_0 = findViewById(R.id.equipment17_abnormal_button);
        RadioButton btn18_1 = findViewById(R.id.equipment18_normal_button);
        RadioButton btn18_0 = findViewById(R.id.equipment18_abnormal_button);
        RadioButton btn19_1 = findViewById(R.id.equipment19_normal_button);
        RadioButton btn19_0 = findViewById(R.id.equipment19_abnormal_button);
        RadioButton btn20_1 = findViewById(R.id.equipment20_normal_button);
        RadioButton btn20_0 = findViewById(R.id.equipment20_abnormal_button);
        RadioButton btn21_1 = findViewById(R.id.equipment21_normal_button);
        RadioButton btn21_0 = findViewById(R.id.equipment21_abnormal_button);
        RadioButton btn22_1 = findViewById(R.id.equipment22_normal_button);
        RadioButton btn22_0 = findViewById(R.id.equipment22_abnormal_button);
        RadioButton btn23_1 = findViewById(R.id.equipment23_normal_button);
        RadioButton btn23_0 = findViewById(R.id.equipment23_abnormal_button);
        RadioButton btn24_1 = findViewById(R.id.equipment24_normal_button);
        RadioButton btn24_0 = findViewById(R.id.equipment24_abnormal_button);
        RadioButton btn25_1 = findViewById(R.id.equipment25_normal_button);
        RadioButton btn25_0 = findViewById(R.id.equipment25_abnormal_button);
        RadioButton btn26_1 = findViewById(R.id.equipment26_normal_button);
        RadioButton btn26_0 = findViewById(R.id.equipment26_abnormal_button);
        RadioButton btn27_1 = findViewById(R.id.equipment27_normal_button);
        RadioButton btn27_0 = findViewById(R.id.equipment27_abnormal_button);
        RadioButton btn28_1 = findViewById(R.id.equipment28_normal_button);
        RadioButton btn28_0 = findViewById(R.id.equipment28_abnormal_button);
        RadioButton btn29_1 = findViewById(R.id.equipment29_normal_button);
        RadioButton btn29_0 = findViewById(R.id.equipment29_abnormal_button);
        RadioButton btn30_1 = findViewById(R.id.equipment30_normal_button);
        RadioButton btn30_0 = findViewById(R.id.equipment30_abnormal_button);
        RadioButton btn31_1 = findViewById(R.id.equipment31_normal_button);
        RadioButton btn31_0 = findViewById(R.id.equipment31_abnormal_button);
        RadioButton btn32_1 = findViewById(R.id.equipment32_normal_button);
        RadioButton btn32_0 = findViewById(R.id.equipment32_abnormal_button);
        normalButtons = new ArrayList<>();
        normalButtons.add(btn1_1);  normalButtons.add(btn2_1);  normalButtons.add(btn3_1);
        normalButtons.add(btn4_1);  normalButtons.add(btn5_1);  normalButtons.add(btn6_1);
        normalButtons.add(btn7_1);  normalButtons.add(btn8_1);  normalButtons.add(btn9_1);
        normalButtons.add(btn10_1); normalButtons.add(btn11_1); normalButtons.add(btn12_1);
        normalButtons.add(btn13_1); normalButtons.add(btn14_1); normalButtons.add(btn15_1);
        normalButtons.add(btn16_1); normalButtons.add(btn17_1); normalButtons.add(btn18_1);
        normalButtons.add(btn19_1); normalButtons.add(btn20_1); normalButtons.add(btn21_1);
        normalButtons.add(btn22_1); normalButtons.add(btn23_1); normalButtons.add(btn24_1);
        normalButtons.add(btn25_1); normalButtons.add(btn26_1); normalButtons.add(btn27_1);
        normalButtons.add(btn28_1); normalButtons.add(btn29_1); normalButtons.add(btn30_1);
        normalButtons.add(btn31_1); normalButtons.add(btn32_1);
        abnormalButtons = new ArrayList<>();
        abnormalButtons.add(btn1_0);  abnormalButtons.add(btn2_0);  abnormalButtons.add(btn3_0);
        abnormalButtons.add(btn4_0);  abnormalButtons.add(btn5_0);  abnormalButtons.add(btn6_0);
        abnormalButtons.add(btn7_0);  abnormalButtons.add(btn8_0);  abnormalButtons.add(btn9_0);
        abnormalButtons.add(btn10_0); abnormalButtons.add(btn11_0); abnormalButtons.add(btn12_0);
        abnormalButtons.add(btn13_0); abnormalButtons.add(btn14_0); abnormalButtons.add(btn15_0);
        abnormalButtons.add(btn16_0); abnormalButtons.add(btn17_0); abnormalButtons.add(btn18_0);
        abnormalButtons.add(btn19_0); abnormalButtons.add(btn20_0); abnormalButtons.add(btn21_0);
        abnormalButtons.add(btn22_0); abnormalButtons.add(btn23_0); abnormalButtons.add(btn24_0);
        abnormalButtons.add(btn25_0); abnormalButtons.add(btn26_0); abnormalButtons.add(btn27_0);
        abnormalButtons.add(btn28_0); abnormalButtons.add(btn29_0); abnormalButtons.add(btn30_0);
        abnormalButtons.add(btn31_0); abnormalButtons.add(btn32_0);
        //设备名称
        TextView name1 = findViewById(R.id.item1);  TextView name2 = findViewById(R.id.item2);
        TextView name3 = findViewById(R.id.item3);  TextView name4 = findViewById(R.id.item4);
        TextView name5 = findViewById(R.id.item5);  TextView name6 = findViewById(R.id.item6);
        TextView name7 = findViewById(R.id.item7);  TextView name8 = findViewById(R.id.item8);
        TextView name9 = findViewById(R.id.item9);  TextView name10 = findViewById(R.id.item10);
        TextView name11 = findViewById(R.id.item11);  TextView name12 = findViewById(R.id.item12);
        TextView name13 = findViewById(R.id.item13);  TextView name14 = findViewById(R.id.item14);
        TextView name15 = findViewById(R.id.item15);  TextView name16 = findViewById(R.id.item16);
        TextView name17 = findViewById(R.id.item17);  TextView name18 = findViewById(R.id.item18);
        TextView name19 = findViewById(R.id.item19);  TextView name20 = findViewById(R.id.item20);
        TextView name21 = findViewById(R.id.item21);  TextView name22 = findViewById(R.id.item22);
        TextView name23 = findViewById(R.id.item23);  TextView name24 = findViewById(R.id.item24);
        TextView name25 = findViewById(R.id.item25);  TextView name26 = findViewById(R.id.item26);
        TextView name27 = findViewById(R.id.item27);  TextView name28 = findViewById(R.id.item28);
        TextView name29 = findViewById(R.id.item29);  TextView name30 = findViewById(R.id.item30);
        TextView name31 = findViewById(R.id.item31);  TextView name32 = findViewById(R.id.item32);
        names = new ArrayList<>();
        names.add(name1);   names.add(name2);   names.add(name3);   names.add(name4);   names.add(name5);
        names.add(name6);   names.add(name7);   names.add(name8);   names.add(name9);   names.add(name10);
        names.add(name11);  names.add(name12);  names.add(name13);  names.add(name14);  names.add(name15);
        names.add(name16);  names.add(name17);  names.add(name18);  names.add(name19);  names.add(name20);
        names.add(name21);  names.add(name22);  names.add(name23);  names.add(name24);  names.add(name25);
        names.add(name26);  names.add(name27);  names.add(name28);  names.add(name29);  names.add(name30);
        names.add(name31);  names.add(name32);
        expandable_1=findViewById(R.id.expandable_1);
        ButtonNo1=findViewById(R.id.button_1);
        expandable_2=findViewById(R.id.expandable_2);
        ButtonNo2=findViewById(R.id.button2);
        expandable_3=findViewById(R.id.expandable_3);
        ButtonNo3=findViewById(R.id.button3);

        //日期
        TextView dateEdit = findViewById(R.id.compost_editDate);
        Calendar calendar=Calendar.getInstance();
        Integer year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH)+1; //第一个月从0开始，所以得到月份＋1
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        dateEdit.setText(year+"-"+month+"-"+day);

        //页面返回按钮
        TitleBar titleBar = findViewById(R.id.titleBar);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            //操作人——如果还有未操作的，提示用户，直到所有都操作
            public void onLeftClick(View v) {finish();}
            @Override
            public void onTitleClick(View v) {}
            @Override
            public void onRightClick(View v) {}
        });

        //equipments
        for (int i = 0; i < names.size(); i++) {
            String eqName = names.get(i).getText().toString();
            RadioButton normal = normalButtons.get(i), abnormal = abnormalButtons.get(i);
            RadioGroup group = radioGroups.get(i);
            Button button = i < 12 ? ButtonNo1 : i < 24 ? ButtonNo2 : i < 27 ? ButtonNo3 : null;
            String sysName = button != null ? button.getText().toString().split(" ")[1] : "";
            normal.setOnClickListener(v -> {
                if (normal.isChecked()) {
                    saveNormal(eqName, normal, abnormal, group, sysName);
                }
            });
            abnormal.setOnClickListener(v -> {
                if (abnormal.isChecked()) {
                    saveAbnormal(eqName, normal, abnormal, group, sysName);
                }
            });
        }

        //获取当天最新一条数据
        RequestQueue queue = Volley.newRequestQueue(this);
        String url = Config.url + "/sjq/SjqDeodorizationProductionDeviceCheck/getlast_day?factory="+factory;
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            if(!jsonObject.isNull("data")) {
                                JSONArray data = jsonObject.getJSONArray("data");
                                if(data.length() > 0){
                                    for(int i = 0; i < data.length(); i++){
                                        // 遍历 jsonarray 数组，把每一个对象转成 json 对象
                                        JSONObject record = data.getJSONObject(i);
                                        // 得到 每个对象中的属性值
                                        for (int j = 0; j < names.size(); j++) {
                                            String eqName = names.get(j).getText().toString();
                                            String sysName = j < 12 ? ButtonNo1.getText().toString().split(" ")[1] + " " :
                                                     j < 24 ? ButtonNo2.getText().toString().split(" ")[1] + " " :
                                                     j < 27 ? ButtonNo3.getText().toString().split(" ")[1] + " " : "";
                                            eqName = sysName + eqName;
                                            RadioButton normal = normalButtons.get(j);
                                            RadioButton abnormal = abnormalButtons.get(j);
                                            if (record.getString("equipmentName").equals(eqName)) {
                                                if(record.get("isNormal").equals("正常")){
                                                    normal.setChecked(true);
                                                }else {
                                                    abnormal.setChecked(true);
                                                }
                                                if(!record.isNull("operator")){
                                                    normal.setClickable(false);
                                                    abnormal.setClickable(false);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(ProductionFacilityCheck.this,
                        "获取信息失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        queue.add(stringRequest);
    }

    public void show1(View view) {
        if (expandable_1.isExpanded()){
            ButtonNo1.setText("+ 固液分离车间除臭系统");
        }else{
            ButtonNo1.setText("- 固液分离车间除臭系统");
        }
        expandable_1.toggle();
    }
    public void show2(View view) {
        if (expandable_2.isExpanded()){
            ButtonNo2.setText("+ 堆肥车间除臭系统");
        }else{
            ButtonNo2.setText("- 堆肥车间除臭系统");
        }
        expandable_2.toggle();
    }
    public void show3(View view) {
        if (expandable_3.isExpanded()){
            ButtonNo3.setText("+ 絮凝车间除臭系统");
        }else{
            ButtonNo3.setText("- 絮凝车间除臭系统");
        }
        expandable_3.toggle();
    }

    public void saveNormal(String equipment_name, RadioButton normal_rb, RadioButton abnormal_rb,
                           RadioGroup rb, String sys_name) {
        new AlertDialog.Builder(this)
                .setTitle("确定 “"+ equipment_name +"” 正常？")
                .setCancelable(false)
                .setNegativeButton("否", ((dialog, which) ->{
                    Toast.makeText(this, "取消保存", Toast.LENGTH_SHORT).show();
                    rb.clearCheck();
                }))
                .setPositiveButton("是", (dialog, which) ->{
                    // 提交表单
                    RequestQueue queue = Volley.newRequestQueue(this);
                    String url = Config.url + "/sjq/SjqDeodorizationProductionDeviceCheck/add_recorder";

                    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    try {
                                        JSONObject jsonObject = new JSONObject(response);
                                        String code = jsonObject.getString("code");
                                        if (code.equals("200")){
                                            normal_rb.setClickable(false);
                                            abnormal_rb.setClickable(false);
                                            Toast.makeText(ProductionFacilityCheck.this,
                                                    "保存成功", Toast.LENGTH_SHORT).show();
                                        }
                                        else {
                                            Toast.makeText(ProductionFacilityCheck.this,
                                                    "保存失败", Toast.LENGTH_SHORT).show();
                                            normal_rb.setChecked(false);
                                        }
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Toast.makeText(ProductionFacilityCheck.this,
                                    "保存失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
                            rb.clearCheck();
                        }
                    }) {
                        @Override
                        protected Map<String, String> getParams() {
                            Map<String, String> map=new HashMap<>();
                            map.put("equipment_name", sys_name + equipment_name);
                            map.put("is_normal","正常");
                            map.put("remarks", "");
                            map.put("operator", name);
                            map.put("factory", factory);
                            return map;
                        }
                    };
                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                    queue.add(stringRequest);
                })
                .show();
    }

    public void saveAbnormal(String equipment_name, RadioButton normal_rb, RadioButton abnormal_rb,
                             RadioGroup rb, String sys_name) {
        final EditText equipment_problem = new EditText(this);
        equipment_problem.setHint("   输入问题:");
        new AlertDialog.Builder(this)
                .setTitle("请填写 “"+ equipment_name +"” 异常原因？")
                .setView(equipment_problem)
                .setCancelable(false)
                .setNegativeButton("取消", ((dialog, which) ->{
                    Toast.makeText(this, "取消保存", Toast.LENGTH_SHORT).show();
                    rb.clearCheck();
                }
                ))
                .setPositiveButton("提交", (dialog, which) ->{
                    // 提交表单
                    RequestQueue queue = Volley.newRequestQueue(this);
                    String url = Config.url + "/sjq/SjqDeodorizationProductionDeviceCheck/add_recorder";

                    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    try {
                                        JSONObject jsonObject = new JSONObject(response);
                                        String code = jsonObject.getString("code");
                                        if (code.equals("200")){
                                            normal_rb.setClickable(false);
                                            abnormal_rb.setClickable(false);
                                            Toast.makeText(ProductionFacilityCheck.this,
                                                    "保存成功", Toast.LENGTH_SHORT).show();
                                        }
                                        else {
                                            Toast.makeText(ProductionFacilityCheck.this,
                                                    "保存失败", Toast.LENGTH_SHORT).show();
                                            abnormal_rb.setChecked(false);
                                        }
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Toast.makeText(ProductionFacilityCheck.this,
                                    "保存失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }) {
                        @Override
                        protected Map<String, String> getParams() {
                            Map<String, String> map=new HashMap<>();
                            map.put("equipment_name", sys_name + equipment_name);
                            map.put("is_normal","异常");
                            map.put("remarks", equipment_problem.getText().toString());
                            map.put("operator", name);
                            map.put("factory", factory);
                            return map;
                        }
                    };
                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                    queue.add(stringRequest);
                })
                .show();
    }
}